<?php
set_time_limit(9999999999999999999999);
$con = mysqli_connect("127.0.0.1","root","","funda_site_2");

$sql = "SELECT woid, ligging1, ligging2, ligging3, ligging4, ligging5, 
     ligging6, ligging7, ligging8 FROM wo
     WHERE ligging1 is not null OR ligging2 is not null 
	OR ligging3 is not null OR ligging4 is not null 
     OR ligging5 is not null OR ligging6 is not null OR ligging7 
    is not null OR ligging8 is not null";
$result = mysqli_query($con,$sql);

while($row = mysqli_fetch_array($result))
{
    for($i=1;$i<= 8;$i++) {
        if($row['ligging'.$i] != null) {
            $sql2="INSERT INTO wo_ligging (woid, ligging_id) 
            VALUES (".$row['woid'].",".$row['ligging'.$i].")";
            mysqli_query($con,$sql2);
        }
    }
    echo mysqli_error($con);
}

?>
